//
//  BVDailyViewController.m
//  XiangYu
//
//  Created by YYKJ on 2017/5/31.
//  Copyright © 2017年 YYKJ. All rights reserved.
//

#import "BVDailyViewController.h"
#import "BVNavsliderView.h"

#import "BVWhoSeenMeViewController.h"
#import "BVMeSeenWhoViewController.h"
#import "BVGoodFeelingViewController.h"

@interface BVDailyViewController ()<UIScrollViewDelegate>

@property (nonatomic ,strong) NSArray           *titleArray;
@property (nonatomic ,strong) UIScrollView      *scrollView;
@property (nonatomic ,strong) NSArray           *controllerArray;

@end

@implementation BVDailyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor BVBackgroundLightGrayColor]];
    
    [self setNav];
    [self layoutUI];
}

#pragma mark - 设置导航栏
-(void)setNav{
    
    //-----------导航栏视图
    BVNavsliderView *nabLider = [[BVNavsliderView alloc]initWithFrame:CGRectMake(60, 0, ScreenW-120, 40)];
    [self.navigationItem setTitleView:nabLider];
    [self.navigationItem.titleView setFrame:CGRectMake(0, 60, ScreenW-120, 44)];
    
    nabLider.btnClick = ^(NSInteger index) {
        
        [self slidingScrollView:index];
    };
    
}

- (void)layoutUI{
    
    self.scrollView = [UIScrollView new];
    [self.view addSubview:self.scrollView];
    [self.scrollView setBackgroundColor:[UIColor blueColor]];
    [self.scrollView setShowsVerticalScrollIndicator:NO];
    [self.scrollView setShowsHorizontalScrollIndicator:NO];
    [self.scrollView setBounces:NO];
    [self.scrollView setContentSize:CGSizeMake(ScreenW*3, ScreenH-64-49)];
    [self.scrollView setUserInteractionEnabled:YES];
    [self.scrollView setDelegate:self];
    [self.scrollView setPagingEnabled:YES];
   // [self.scrollView setScrollEnabled:NO];
    self.scrollView.sd_layout
    .topSpaceToView(self.view, 0)
    .leftSpaceToView(self.view, 0)
    .widthIs(ScreenW)
    .bottomSpaceToView(self.view, 49);
    
    // ---------  添加子控制器
    BVWhoSeenMeViewController    *realTimeVC = [[BVWhoSeenMeViewController alloc]init];
    BVMeSeenWhoViewController    *listVC     = [[BVMeSeenWhoViewController alloc]init];
    BVGoodFeelingViewController  *pendingVC  = [[BVGoodFeelingViewController alloc]init];
    
    self.controllerArray = @[realTimeVC,listVC,pendingVC];
    
    for (int i = 0; i < _controllerArray.count; i++) {
        UIView *viewcon = [[UIView alloc]
                           initWithFrame:CGRectMake(ScreenW*i, 0, ScreenW, ScreenH)];
        UIViewController *viewcontroller = self.controllerArray[i];
        viewcon = viewcontroller.view;
        
        [viewcon setFrame:CGRectMake(ScreenW*i, 0, ScreenW, ScreenH)];
        [self.scrollView addSubview:viewcon];
    }
    
    
}

#pragma mark - 获得滑动按钮的点击  移动scrllView的偏移量
- (void)slidingScrollView:(NSInteger )integer{
    
    [UIView animateWithDuration:0.1 animations:^{
        self.scrollView.contentOffset = CGPointMake(ScreenW*integer , 0);
    }];
    
}

#pragma mark - 监听滚动事件判断当前拖动到哪一个了
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
{
    NSInteger index = scrollView.contentOffset.x / ScreenW;
    
    [[NSNotificationCenter defaultCenter]postNotification:[NSNotification notificationWithName:@"123" object:nil userInfo:@{@"index":[NSString stringWithFormat:@"%ld",(long)index]}]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
